package com.cat.practice;

/**
 * @author cat
 * @description https://leetcode.cn/problems/reschedule-meetings-for-maximum-free-time-i/
 * 未完成
 * @create 2025/7/22 20:55
 * @since JDK17
 */

public class Solution02 {
    public int maxFreeTime(int eventTime, int k, int[] startTime, int[] endTime) {
        int n = startTime.length, ans = 0, sum = 0, s, e;
        for (int l = 0, r = 0; r < n; ) {
            s = startTime[l];
            while (r < n && r - l <= k + 1) {
                sum += endTime[r] - startTime[r];   // 求和
                r++;
            }
            e = endTime[r - 1];
            ans = Math.max(ans, (e - s) - sum);
            sum -= endTime[l] - startTime[l];
            l++;
        }
        return ans;
    }
}
